{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "6b483d54-5aac-46fd-baa7-4bc7083d6e67",
   "metadata": {},
   "source": [
    "https://leetcode.com/problems/restore-ip-addresses\n",
    "\n",
    "\n",
    "Runtime: 48 ms, faster than 34.87% of Python3 online submissions for Restore IP Addresses.\n",
    "Memory Usage: 14.2 MB, less than 65.76% of Python3 online submissions for Restore IP Addresses.\n",
    "\n",
    "\n",
    "```python\n",
    "import re\n",
    "from itertools import combinations\n",
    "\n",
    "class Solution:\n",
    "    def restoreIpAddresses(self, s: str) -> List[str]:\n",
    "        #9:37\n",
    "        def isIpValid(ip):\n",
    "            check = re.match(r'^(?:[0-9]{1,3}\\.){3}[0-9]{1,3}$', ip)\n",
    "            if check:\n",
    "                return True\n",
    "            else:\n",
    "                return False\n",
    "        \n",
    "        theResult = []\n",
    "        theIndexRange = range(0, len(s)+1)\n",
    "        for oneWay in combinations(theIndexRange, 4):\n",
    "            a,b,c,d = oneWay\n",
    "            if d == len(s):\n",
    "                parts = [s[:a], s[a:b], s[b:c], s[c:d]]\n",
    "                tempIP = \".\".join(parts)\n",
    "                if isIpValid(tempIP):\n",
    "                    if all([int(i)<=255 and not (len(i) > 1 and i[0] == \"0\") for i in parts]):\n",
    "                        #print(oneWay, tempIP)\n",
    "                        theResult.append(tempIP)\n",
    "        return theResult\n",
    "        #9:49\n",
    "        #debug until 9:59\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "12fee82e-f86c-45fe-98d7-a3f5dcba4e31",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
